//
//  CompareDesignOrderDetailVC.m
//  ForestPack
//
//  Created by jimmy on 2018/7/24.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#pragma mark - 这个是1.比稿设计（设计师已完成）界面  2.完成付款待评价界面  3.确定雇佣  4.雇主
#import "CompareDesignOrderDetailVC.h"
#import "OrderStateTableViewCell.h"
#import "OrderDetailFirstCell.h"
#import "BilledPieceCell.h"
#import "OrderDetailHeaderView.h"
#import "SystemEmployerCell.h"

@interface CompareDesignOrderDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)  BaseTableView  * tableView;

@end

@implementation CompareDesignOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"订单详情"];
    [self setTableViewUI];
    
}

-(void)setTableViewUI
{
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}

#pragma mark - tableView的delegate和datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section == 3) {
//        if (9.确定雇佣  10.雇主) {
//            return 1;
//        }
        return 6;
    }
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 94;
    }else if (indexPath.section == 1){
        return 108;
    }else if(indexPath.section == 2){
        return 131;
    }else{
//        if (9.确定雇佣  10.雇主) {
//            return 0.01;
//        }
        return 44;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 0.01;
    }else if(section == 0){
        //if(9.确定雇佣  10.雇主){
//              return 44;
        //}
        return 0.01;
    }else if(section == 1){
        ///交易中，设计师已接单的界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            return 79;
        }
        ///完成付款待评价界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
              return 79;
        }
        
        return 0.01;
    }else{
//        if(9.确定雇佣  10.雇主){
//              return 200;
        //}
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            return 44;
        }
        return 0.01;
    }
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2 ) {
        UIView *view = [[UIView alloc] init];
        return view;
    }else if (section == 0){
        ///完成付款待评价界
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            UIView *view = [[UIView alloc] init];
            return view;
        }
        ///交易中，设计师已接单的界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            UIView *view = [[UIView alloc] init];
            return view;
        }
        //if(9.确定雇佣  10.雇主){
        //      UIView *view = [[UIView alloc] init];
//        UILabel *label = [[UILabel alloc] init];
//        label.frame = CGRectMake(13, 10, 80, 24);
//        label.text = @"设计师";
//        label.textAlignment = NSTextAlignmentLeft;
//        label.font = Kfont(14);
//        label.textColor = FONTCOLOR_BLACK;
//        [view addSubview:label];
//        UILabel *lineLabel = [[UILabel alloc] init];
//        lineLabel.frame = CGRectMake(0, 43, SCREEN_WIDTH, 1);
//        lineLabel.backgroundColor = LineColor;
//        [view addSubview:lineLabel];
//        view.backgroundColor = [UIColor whiteColor];
//        return view;
        //}
        UIView *view = [[UIView alloc] init];
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(13, 10, 80, 24);
        label.text = @"设计师";
        label.textAlignment = NSTextAlignmentLeft;
        label.font = Kfont(14);
        label.textColor = FONTCOLOR_BLACK;
        [view addSubview:label];
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.frame = CGRectMake(0, 43, SCREEN_WIDTH, 1);
        lineLabel.backgroundColor = LineColor;
        [view addSubview:lineLabel];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }
    else if(section == 1){
        ///完成付款待评价界
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            OrderDetailHeaderView *view = [OrderDetailHeaderView headerViewWithHeight:79];
            view.backgroundColor = [UIColor whiteColor];
            return view;
        }
        ///交易中，设计师已接单的界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            OrderDetailHeaderView *view = [OrderDetailHeaderView headerViewWithHeight:79];
            view.backgroundColor = [UIColor whiteColor];
            return view;
        }
        UIView *view = [[UIView alloc] init];
        return view;
    }else{
        ///交易中，设计师已接单的界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            UIView *view = [[UIView alloc] init];
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(13, 10, 80, 24);
            label.text = @"竞标人";
            label.textAlignment = NSTextAlignmentLeft;
            label.font = Kfont(14);
            label.textColor = FONTCOLOR_BLACK;
            [view addSubview:label];
            UILabel *lineLabel = [[UILabel alloc] init];
            lineLabel.frame = CGRectMake(0, 43, SCREEN_WIDTH, 1);
            lineLabel.backgroundColor = LineColor;
            [view addSubview:lineLabel];
            view.backgroundColor = [UIColor whiteColor];
            return view;
        }
//        if (9.确定雇佣) {
//            UIView *view = [[UIView alloc] init];
//            OperateButton *button = [[OperateButton alloc] initWithFrame:CGRectMake(13, 60, SCREEN_WIDTH - 26, 44)];
//            [button setTitle:@"确定雇佣" forState:UIControlStateNormal];
//            [view addSubview:button];
//            return view;
        //}else if(10.雇主){
        //    UIView *view = [[UIView alloc] init];
        //    OperateButton *button = [[OperateButton alloc] initWithFrame:CGRectMake(13, 60, SCREEN_WIDTH - 26, 44)];
        //    [button setTitle:@"等待设计师确认" forState:UIControlStateNormal];
        //    [view addSubview:button];
        //    return view;
        //}
        UIView *view = [[UIView alloc] init];
//        OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(13, 60, SCREEN_WIDTH - 26, 44);
//        [button setTitle:@"确定雇佣" forState:UIControlStateNormal];
//        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        view.backgroundColor = [UIColor whiteColor];
//        [view addSubview:button];
        return view;
        
        
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 3) {
//        if (9.确定雇佣  10.雇主) {
//            return 10;
//        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            return 180;
        }
        return 10;
    }
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 3) {
        ///完成付款待评价界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            UIView *view = [[UIView alloc] init];
            OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(13, 30, SCREEN_WIDTH - 26, 44);
            [button setTitle:@"立即评价" forState:UIControlStateNormal];
            [view addSubview:button];
            view.backgroundColor = [UIColor whiteColor];
            return view;
        }
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }
    UIView *view = [[UIView alloc] init];
    return view;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        ///完成付款待评价界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            OrderStateTableViewCell *cell = [OrderStateTableViewCell cellWithTableView:tableView andIndexPath:indexPath andTitle:@"已完成付款，待评价"];
            return cell;
        }
        ///交易中，设计师已接单的界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            OrderStateTableViewCell *cell = [OrderStateTableViewCell cellWithTableView:tableView andIndexPath:indexPath andTitle:@"设计师已接单"];
            return cell;
        }
//        OrderStateTableViewCell *cell = [OrderStateTableViewCell cellWithTableView:tableView andIndexPath:indexPath andTitle:@"设计师已完成"];
        SystemEmployerCell *cell = [SystemEmployerCell cellWithTableView:tableView indexPath:indexPath];
        cell.finishBtn.hidden = YES;
        return cell;
    }else if (indexPath.section == 1){
        OrderDetailFirstCell *cell = [OrderDetailFirstCell cellWithTableView:tableView indexPath:indexPath];
        return cell;
    }else if(indexPath.section == 2){
        OrderInfoCell *cell = [OrderInfoCell cellWithTableView:tableView indexPath:indexPath];
        return cell;
    }else{
        ///完成付款待评价界面
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"4"]) {
            BilledSeeDetailCell *cell = [BilledSeeDetailCell cellWithTableView:tableView indexPath:indexPath];
            return cell;
        }
        ///交易中，设计师已接单的界面(此处需要修改)
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"3"]) {
            BilledSeeDetailCell *cell = [BilledSeeDetailCell cellWithTableView:tableView indexPath:indexPath];
            return cell;
        }
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}

@end
